# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html







# from pymongo import MongoClient
#
# client = MongoClient()
# collection = client["tencent"]['hr']

class TencentPipeline(object):
    def process_item(self, item, spider):
        print(item)
        # collection.insert(item)
        return item

"""
注意1：如果在spider中yield到pipeline中的是一个BaseItem对象，不能直接“collection.insert(item)”——像字典，但又不是字典
collection.insert(dict(item))——强制转换

注意2：我们可以在items.py中定义多个item类，然后进行不同的处理
from pymongo import MongoClient
from tencent.items import TencentItem

client = MongoClient()
collection = client["tencent"]['hr']

class TencentPipeline(object):
    def process_item(self, item, spider):
        if isinstance(item,TencentItem):
            print(item)
            collection.insert(dict(item))
        return item
"""

